package com.miku.db.sys.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Index;

import com.google.common.collect.Lists;

/**
 * 系统用户基本表
 * @author 杜金伟 [2016年3月23日 下午5:35:22]
 */
@Entity
@Table(name="sys_user")
@Inheritance(strategy = InheritanceType.JOINED) 
public class SysUser {
	private int id;
	private String loginName;		//用户登录帐号
	private String nickname;			//用户名
	private Date lastlogin;				//最后登录时间
	private String lastloginIP;		//最后一次登录的ip
	private Date prevlogin;			//前一次登录时间
	private String prevloginIP;		//前一次登录的ip
	private String allowloign="yes";		//是否允许登录，默认允许
	private String password;			//密码
	private Date createTime;			//创建时间
	private List<SysRole> roles = Lists.newArrayList();
	
	public String getLastloginIP() {
		return lastloginIP;
	}

	public void setLastloginIP(String lastloginIP) {
		this.lastloginIP = lastloginIP;
	}

	public Date getPrevlogin() {
		return prevlogin;
	}

	public void setPrevlogin(Date prevlogin) {
		this.prevlogin = prevlogin;
	}

	public String getPrevloginIP() {
		return prevloginIP;
	}

	public void setPrevloginIP(String prevloginIP) {
		this.prevloginIP = prevloginIP;
	}

	@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
	public List<SysRole> getRoles() {
		return roles;
	}

	public void setRoles(List<SysRole> roles) {
		this.roles = roles;
	}

	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Index(name = "loginName")
	@Column(columnDefinition="varchar(32)")
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName == null ? null : loginName.trim();
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname == null ? null : nickname.trim();
	}

	public Date getLastlogin() {
		return lastlogin;
	}

	public void setLastlogin(Date lastlogin) {
		this.lastlogin = lastlogin;
	}

	public String getAllowloign() {
		return allowloign;
	}

	public void setAllowloign(String allowloign) {
		this.allowloign = allowloign == null ? null : allowloign.trim();
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password == null ? null : password.trim();
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
}